<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: ind.class.bezugstoffe_1.php 506 2014-01-31 16:44:29Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 506 $
* 	zuletzt geaendert von:	$Author: $
* 	Datum:					$Date: 2014-01-31 16:44:29 +0000 (Fri, 31 Jan 2014) $
*
* 	extends by dirk.mueller (edv-mueller.com)
* 	http://www.itdotmedia.de
*
* --------------------------------------------------------------------------------------
* 	based on:
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
* 	Copyright (c) since 2011 SEO:mercari
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */
include_once (DIR_WS_INCLUDES.'modules/product_konfigurator/ind.class.bezugstoffe.php');

class bezugstoffe_1 extends bezugstoffe {

  function assign_template(&$smarty, $product_id, $with_form_action) {
    global $db;

    $option_smarty = new Smarty();
    if (!$this->assign_template_base($option_smarty, $product_id, $with_form_action)) return;
    $template_name = $option_smarty->getTemplateVars('TEMPLATE');

    $sql = "
      select
      	concat('F|', po.konfigurator_option) konfigurator_option, po.price,
        o.konfigurator_options_name, o.konfigurator_options_parameter, 
      	od.bezug_id, od.bezug_name, od.bezug_img
      from
      	".TABLE_KONFIGURATOR_PRODUCT_OPTION." po
      	inner join ".TABLE_KONFIGURATOR_OPTIONS." o
      		on po.konfigurator_option = o.konfigurator_options_id
      	inner join ".TABLE_KONFIGURATOR_OPTIONS_DETAILS_BEZUGSTOFFE." od
      		on o.konfigurator_options_id = od.bezug_option_id
      where
      	po.product_id = '".$product_id."'
      	and po.konfigurator_option_group = '".$this->group['id']."'
      	and po.konfigurator_option != 'HAVE_TO'
      order by
      	o.konfigurator_options_sort,
      	po.konfigurator_option,
      	od.bezug_name";
//die($sql);      	
    $this->assign_template_bezugstoffe($smarty, $product_id, $sql, $with_form_action);
  }

  function get_price($product_id, $price, $post) {
    global $db;
    $price_value = 0;

    if (!isset($post[$this->group['id']]) || $post[$this->group['id']] == '' ) return $price;

    $sql = "
      select
        product_id, price
      from
        ".TABLE_KONFIGURATOR_PRODUCT_OPTION." po
        inner join ".TABLE_KONFIGURATOR_OPTIONS_DETAILS_BEZUGSTOFFE." od
          on po.konfigurator_option = od.bezug_option_id
      where
        po.product_id = '".$product_id."'
        and konfigurator_option_group = '".$this->group['id']."'
        and od.bezug_id = '".$post[$this->group['id']]."'";
    return parent::get_price_bezugstoffe($sql, $price);
  }
  
  function get_description($product_id, $post) {
    $description = array('option_name' => '', 'option_value' => '');
    if (!isset($post[$this->group['id']]) || $post[$this->group['id']] == '' ) return $description;

    $sql = "
      select
  			po.product_id, po.konfigurator_option,
  			og.konfigurator_optiongroups_name, o.konfigurator_options_name,
  			od.bezug_name
      from
      	".TABLE_KONFIGURATOR_PRODUCT_OPTION." po
      	inner join ".TABLE_KONFIGURATOR_OPTIONGROUPS." og
      		on og.konfigurator_optiongroups_id = po.konfigurator_option_group
      	inner join ".TABLE_KONFIGURATOR_OPTIONS_DETAILS_BEZUGSTOFFE." od
      		on
      			(po.konfigurator_option = od.bezug_option_id and od.bezug_id = '".$post[$this->group['id']]."')
      	inner join ".TABLE_KONFIGURATOR_OPTIONS." o
      		on o.konfigurator_optiongroups_id = 'BEZUGSTOFFE'
      		and o.konfigurator_options_id = od.bezug_option_id
      where
      	po.product_id = '".$product_id."'
      	and po.konfigurator_option_group = '".$this->group['id']."'";
    return $this->get_description_bezugstoffe($sql, $description);
  }
  
}